//
//  VerifyViewController.m
//  bluetooth
//
//  Created by 周季阳 on 15/7/14.
//  Copyright (c) 2015年 switch. All rights reserved.
//

#import "VerifyViewController.h"
#import "UIViewAdditions.h"
#import "UserAgreementViewController.h"
#import "AppDelegate.h"
#import "MainViewController.h"
#import "LeftViewController.h"

@interface VerifyViewController ()<UITextFieldDelegate,UIScrollViewDelegate>
{
    UIScrollView *zScrollView;
    UITextField *zVerifyText;
}


@end

@implementation VerifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     [self initUI];
}
#pragma mark - initUI
-(void)initUI{
    UIWindow *windows = [[[UIApplication sharedApplication] delegate] window];

    zScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, -20, SCREEN_WIDTH, SCREEN_HEIGHT+20)];
    if (SCREEN_HEIGHT<500) {
        zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT+50);
    }else{
        zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-20);
    }
    zScrollView.userInteractionEnabled = YES;
    [self.view addSubview:zScrollView];
    
    
    UIImageView *backImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [backImg setImage:[UIImage imageNamed:@"登陆"]];
    backImg.userInteractionEnabled = YES;
    [zScrollView addSubview:backImg];
    
    UIImageView *textImg = [[UIImageView alloc]initWithFrame:CGRectMake(10, backImg.frame.size.height/2,160, 37)];
    [textImg setImage:[UIImage imageNamed:@"验证_03"]];
    textImg.userInteractionEnabled = YES;
    [zScrollView addSubview:textImg];
    
    zVerifyText = [[UITextField alloc] initWithFrame:CGRectMake(15, 0 ,textImg.frame.size.width-20 , 37)];
    zVerifyText.tag = 1;
    zVerifyText.placeholder = @"请输入验证码";
    zVerifyText.font = [UIFont systemFontOfSize:13];
    [textImg addSubview:zVerifyText];
    zVerifyText.delegate = self;
    
    UIButton *rBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rBtn.frame = CGRectMake(textImg.right+10, textImg.top,130, 40);
    [rBtn setBackgroundImage:[UIImage imageNamed:@"验证_05"] forState:UIControlStateNormal];
    [rBtn addTarget:self action:@selector(clickRBtn) forControlEvents:UIControlEventTouchUpInside];
    [zScrollView addSubview:rBtn];

    
    UILabel *textLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, textImg.bottom+5, 117, 20)];
    textLabel.text = @"点击注册及表示同意";
    textLabel.textColor = [UIColor whiteColor];
    textLabel.textAlignment = NSTextAlignmentLeft;
    textLabel.font = [UIFont systemFontOfSize:13];
    [zScrollView addSubview:textLabel];
    
    UIButton *textBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    textBtn.frame = CGRectMake(textLabel.right+5, textLabel.top, 52, 20);
    [textBtn setTitle:@"用户协议" forState:UIControlStateNormal];
    textBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [textBtn addTarget:self action:@selector(clickTextBtn) forControlEvents:UIControlEventTouchUpInside];
    [zScrollView addSubview:textBtn];
    
    UIButton *zBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    zBtn.frame = CGRectMake(10, textBtn.bottom+10, SCREEN_WIDTH-20, 37);
    [zBtn setBackgroundImage:[UIImage imageNamed:@"验证_09"] forState:UIControlStateNormal];
    [zBtn addTarget:self action:@selector(clickZBtn) forControlEvents:UIControlEventTouchUpInside];
    [backImg addSubview:zBtn];
    
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    [singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [zScrollView addGestureRecognizer:singleTapGestureRecognizer];
    
    
}
#pragma mark - 点击用户协议
-(void)clickTextBtn{
    UserAgreementViewController *user = [[UserAgreementViewController alloc]init];
    [self.navigationController pushViewController:user animated:YES];
}
#pragma mark - 发送验证码
-(void)clickRBtn{
    
}
#pragma marj - 验证
-(void)clickZBtn{
        AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        // 在delegate中初始化新的controller
        //[delegate initTabbarController];
        // 修改rootViewController
        MainViewController *mainVC = [MainViewController new];
        LeftViewController *leftVC = [[LeftViewController alloc] init];
        UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:leftVC];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainVC];
        SLideZoomMenuController *slideZoomMenu = [[SLideZoomMenuController alloc] initWithRootController:nav];
        slideZoomMenu.leftViewController = nav1;
        
        [delegate.window addSubview:slideZoomMenu.view];
        [self.view removeFromSuperview];
        delegate.window.rootViewController = slideZoomMenu;
   
}
#pragma mark - 点击屏幕空白区域
-(void)singleTap{
    [zVerifyText resignFirstResponder];
}
#pragma mark - UItextField Delegate
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    zScrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+100);
    [zScrollView setContentOffset:CGPointMake(0, 100) animated:YES];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    zScrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
    return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    [textField resignFirstResponder];
    zScrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
